/****************************************************************************
*
*  ALi Corporation, All Rights Reserved. 2007 Copyright (C)
*
*  File: atsc_cc_init.c
*
*  Description: PSIP parsing engine to monitor and parse tables in streams 
*  History:
*      Date        	Author         	Version   Comment
*      ====        	======         =======   =======
*  1.  ----		Steve Lee         0.1.000		Initial
*  2.  2007.  		HB Chen      	  0.2.000   	modify, rename
****************************************************************************/
/*******************
* INCLUDE FILES    *
********************/
#include <sys_config.h>
#include <osal/osal.h>
#include <basic_types.h>
#include <Mediatypes.h>

#include <api/libc/printf.h>
#include <api/libc/alloc.h>
#include <api/libc/string.h>

#include <hld/hld_dev.h>
#include <hld/vbi/vbi.h>
#include <hld/vbi/vbi_dev.h>
#include <hld/dis/vpo.h>

#include <api/libclosecaption/atsc_cc_init.h>//vbi_m3327_cc_init.h
#include <api/libclosecaption/closecaption_osd.h> //vicky20110128
#if 1// (SYS_CHIP_MODULE!=ALI_M3327C)&&((SYS_PROJECT_FE == PROJECT_FE_ATSC)||(SYS_PROJECT_FE == PROJECT_FE_DVBS)) //vicky20101229 dbg
/*******************
* EXPORTED DATA    *
********************/
#define USER_DATA_LENGTH_MAX	210//104//xing for DTVCC
#define USER_DATA_ARRAY_MAX	20//10
extern UINT8 g_user_data[USER_DATA_ARRAY_MAX][USER_DATA_LENGTH_MAX];
extern INT32 g_user_data_array_cnt;
extern INT32 g_user_data_array_rd;
extern struct vbi_config_par *ccg_vbi27_pconfig_par;	//vicky20101229 dbg rename
extern UINT8 g_dtv_cc_service;
/*******************
* LOCAL MACROS     *
********************/

/*******************
* STATIC DATA      *
********************/

/*******************
* LOCAL TYPEDEFS   *
********************/

/*******************
* GLOBAL DATA   *
********************/
UINT16 *ccg_vbi27_dtvcc_by_osd=NULL;	//rename //vicky20110111dbg
UINT8 *ccg_vbi27_cc_by_osd = NULL;	//rename //vicky20110111dbg
BOOL ccg_disable_process_cc=FALSE;	//rename //vicky20110111dbg
BOOL g_disable_vbioutput=FALSE;		
BOOL clean_cc_buffer=FALSE;
BOOL ccrecv_PAC=FALSE;				//rename //vicky20110111dbg
UINT32 ccvbi_rating=0;					//rename //vicky20110111dbg
UINT32 ccpre_vbi_rating=0;				//rename //vicky20110111dbg
BOOL ccvbi_CC=FALSE;					//rename //vicky20110111dbg
UINT8 ccvbi_cgmsa = 0;					//for cgmsa
static struct vbi_m3327_private *g_vbi_priv;
struct vbi_config_par *ccg_vbi27_pconfig_par = NULL;
char ccvbi_m3327_name[HLD_MAX_NAME_SIZE] = "CCVBI_M3327_0";	//vicky20101229 dbg rename
UINT8 *ccg_vbi27_ttx_by_osd = NULL;	//vicky20101229 dbg rename
static char *g_vbi_m3327_name = NULL;

//vicky20110128
struct atsc_cc_config_par g_atsc_cc_config_par; //vicky20110128
BOOL gfCCAttach=FALSE;	//vicky20110224
void lib_atsc_cc_attach(struct atsc_cc_config_par *pcc_config_par)
{
	if(NULL == pcc_config_par)
    {
		VBI_PRINTF("Oh!Oh!, Forgot to set atsc_cc_config_par: ex Bitstream /Draw Area Buf Addr, OSD Layer!!\n");
    }
	else
	{
		MEMCPY(&g_atsc_cc_config_par, pcc_config_par, sizeof(struct atsc_cc_config_par));
		gfCCAttach=TRUE;
		VBI_PRINTF("%s() Done !!\n",__FUNCTION__);
	}	
}

/********************************************
* NAME: vbi_cc_init
*       init cc parameters and set callback fucn of vpo_isr to excute push user data for cc using
*
* Returns : BOOL
*              1 		: RET_FAILURE
*              0		: RET_SUCCESS
* Parameter     				Flow    Description
* ------------------------------------------------------------------------------
* None
* ------------------------------------------------------------------------------
* Additional information:
******************************************/
__ATTRIBUTE_REUSE_
INT32 vbi_cc_init()
{
	struct vbi_device *dev;
	struct vbi_m3327_private *tp;
	void *priv_mem;

	//vicky20110224	error handle while "never call lib_atsc_cc_attach() previously".	
	if(!gfCCAttach)
	{
		VBI_PRINTF("Oh!Oh!no call lib_atsc_cc_attach() first. Use Default Parameter");
		g_atsc_cc_config_par.bs_buf_len=0x1c00;
		g_atsc_cc_config_par.pb_buf_len=0x45780;
		g_atsc_cc_config_par.osd_layer_id=1;
		g_atsc_cc_config_par.cc_width=576;
		g_atsc_cc_config_par.cc_height=390;
		g_atsc_cc_config_par.wPollingTime=500;
		g_atsc_cc_config_par.bCCScan=4;
		g_atsc_cc_config_par.bDTVCCScan=4;
		g_atsc_cc_config_par.bs_buf_addr=(UINT8*)MALLOC(g_atsc_cc_config_par.bs_buf_len);
		g_atsc_cc_config_par.pb_buf_addr=(UINT8*)MALLOC(g_atsc_cc_config_par.pb_buf_len);	
		if(g_atsc_cc_config_par.bs_buf_addr==NULL)
			VBI_PRINTF("Fail to alloc mem for CC BitStream\n");
		if(g_atsc_cc_config_par.bs_buf_addr==NULL)
			VBI_PRINTF("Fail to alloc mem for CC Picture buffer\n");
	}
	//End
	
	g_vbi_m3327_name = (char *)ccvbi_m3327_name;
	
	dev = dev_alloc(g_vbi_m3327_name,HLD_DEV_TYPE_VBI,sizeof(struct vbi_device));
	if (dev == NULL)
	{
		VBI_PRINTF("Error: Alloc video vbiplay device error!\n");
		return RET_FAILURE;
	}
	/* Alloc structure space of private */
	priv_mem = (void *)MALLOC(sizeof(struct vbi_m3327_private));
	if (priv_mem == NULL)
	{
		dev_free(dev);
		VBI_PRINTF("Alloc vbiplay device prive memory error!/n");
		return RET_FAILURE;
	}
	MEMSET(priv_mem, 0, sizeof(struct vbi_m3327_private));
	
	g_vbi_priv = dev->priv =  tp = (struct vbi_m3327_private *)priv_mem;

	ccg_vbi27_pconfig_par = &(g_vbi_priv->config_par);
	ccg_vbi27_ttx_by_osd = &(g_vbi_priv->ttx_by_osd);
	ccg_vbi27_cc_by_osd = &(g_vbi_priv->cc_by_osd);
	//======================================
#ifdef CC_BY_OSD
	ccg_vbi27_dtvcc_by_osd=&(g_vbi_priv->dtvcc_by_osd);//hbchen
#endif
	//======================================
	/*according the macro , config the VBI driver*/
  //vbi_data_array = (struct vbi_data_array_t *)MALLOC((VBI_QUEUE_DEPTH)*sizeof(struct vbi_data_array_t));
  //MEMSET(vbi_data_array, 0, (VBI_QUEUE_DEPTH)*sizeof(struct vbi_m3327_private));	
	

	*ccg_vbi27_ttx_by_osd = FALSE;
	g_vbi_priv->init_ttx_decoder = NULL;

#ifdef	CC_BY_OSD
	*ccg_vbi27_cc_by_osd = TRUE;
	g_vbi_priv->init_cc_decoder = vbi_m3327_init_cc_decoder;
	g_vbi_priv->vbi_line21_push_by_cc = vbi_line21_push;
	g_vbi_priv->vbi_line21_push_by_dtvcc = vbi_line21_push_dtvcc;//xing for DTVCC
#else
	*ccg_vbi27_cc_by_osd = FALSE;
#endif


#ifdef	CC_BY_VBI
	ccg_vbi27_pconfig_par->cc_by_vbi = TRUE;
#else
	ccg_vbi27_pconfig_par->cc_by_vbi = FALSE;
#endif

	//dev->setoutput = vbi_m3327_setoutput;

	dev->next = NULL;
       dev->flags = 0;
	/* Function point init */
	dev->init = vbi_cc_init;

	dev->open = vbi_cc_open;
	dev->close = NULL;
	dev->request_write = NULL;
	dev->update_write = NULL;
	dev->setoutput = ccvbi_m3327_setoutput;
	dev->start = NULL;
	dev->stop = NULL;

	/* Add this device to queue */
	if(dev_register(dev) != RET_SUCCESS)
	{
		VBI_PRINTF("Error: Register vbiplay device error!\n");
		FREE(priv_mem);
		dev_free(dev);
		return RET_FAILURE;
	}
	return RET_SUCCESS;
}


/********************************************
* NAME: atsc_user_data_cc
*       callback func to: 1 vbi output, 2 push user data for cc and dtvcc using
*
* Returns : void
*
* Parameter     				Flow    Description
* ------------------------------------------------------------------------------
* UINT8 FieldPolar				IN		no use
* ------------------------------------------------------------------------------
* Additional information:
******************************************/
//vicky20110302 dbg
//static DWORD dwF1cnt=0;
//static DWORD dwF2cnt=0;
static void atsc_user_data_cc(UINT8 FieldPolar)
{
	UINT8 i=0,j=0,cc_cnt=0;
	UINT8 byte1,byte2, pariety_check_1=0,pariety_check_2=0;
	UINT8 cc_field=0;
	BOOL push_1=FALSE, push_2=FALSE;
	static BOOL XDS=FALSE;
	//if(FieldPolar == 0) return;// current is Top field linemeet ,return
	
		
	UINT8 rd_idx;
	//g_vbi_priv->vbi_line21_push_by_cc((((g_user_data[rd_idx][i*3+8])&0X7F)<<8)|(g_user_data[rd_idx][i*3+9])&0X7F);
	//
	//vicky20110124
	#define SUPPORT_PAL		
	enum TVSystem tvsys;	
	
	#ifndef SUPPORT_PAL
	if(g_user_data_array_cnt>0)
	#else
	UINT8 bRun=1;
	vpo_ioctl((struct vpo_device *)dev_get_by_type(NULL, HLD_DEV_TYPE_DIS), VPO_IO_GET_OUT_MODE, (UINT32)(&tvsys));
	if((tvsys == NTSC)||(tvsys == NTSC_443))
	{
		//no need to run twice.		
		//libc_printf("NTSC");
	}
	else
	{
		bRun=2; //need to run twice.
		//libc_printf("PAL");
	}	
	while( bRun && (g_user_data_array_cnt>0))
	#endif
	{
		#ifdef SUPPORT_PAL
		bRun--;
		#endif
		rd_idx = g_user_data_array_rd;
		if(g_user_data[rd_idx][0]==0x47			//'G'
			&&g_user_data[rd_idx][1]==0x41		//'A'
			&&g_user_data[rd_idx][2]==0x39		//'9'
			&&g_user_data[rd_idx][3]==0x34		//'4'
			&&g_user_data[rd_idx][4]==0x03		//cc indicator
			&&(g_user_data[rd_idx][5]&0x40)==0x40		//process_cc_data_flag
		)
		{
			cc_cnt = g_user_data[rd_idx][5]&0x1f;
			/*
			if(*ccg_vbi27_cc_by_osd != 0)
				cc_cnt = (cc_cnt>2)?2:cc_cnt;// xing 20070522 for DTVCC unused
				*/
			//em_data = g_user_data[6];
			//ccvbi_CC=FALSE;
			for(i=0;i<cc_cnt;i++)
			{
				if((g_user_data[rd_idx][i*3+7]&0x04) == 0x04)//cc_valid == 1
				{
					pariety_check_1=0;pariety_check_2=0;
					byte1=(g_user_data[rd_idx][i*3+8])&0x7F;
					byte2=(g_user_data[rd_idx][i*3+9])&0x7F;			
					#if 1 //for cgmsa
					if((byte1==0x01 && byte2==0x05)||(byte1==0x01 && byte2==0x08)||(byte1==0x09 && byte2==0x01) || (byte1==0x09 && byte2==0x02) \
						|| (byte1==0x0a && byte2==0x01) || (byte1==0x0a && byte2==0x02) ) //v-chip ,CGMS-A, puplic service & puplic service cont.
					#else
					if((byte1==0x01 && byte2==0x05) ||(byte1==0x09 && byte2==0x01) || (byte1==0x09 && byte2==0x02) \
						|| (byte1==0x0a && byte2==0x01) || (byte1==0x0a && byte2==0x02) ) //v-chip , puplic service & puplic service cont.
					#endif
						XDS=TRUE;
					if((byte1>=0x10&&byte1<=0x1f)&&(!(byte2>0x2f&&byte2<0x40)) && byte2>=0x20&&byte2<=0x7f)//control data
						XDS=FALSE;
					//===
					if((byte1>=0x10&&byte1<=0x1f)&&(!(byte2>0x2f&&byte2<0x40)) && byte2>=0x20&&byte2<=0x7f && \
						(!((byte1==0x12 || byte1==0x13|| byte1==0x1A|| byte1==0x1B) && (byte2>0x1f&&byte2<0x40)  )))
					{
						ccvbi_CC=TRUE;
					}
					//===
                    #ifdef CC_MONITOR_CC		 
		        	AddCC();
	            	#endif	
					push_1 = (*ccg_vbi27_cc_by_osd==0x00 || *ccg_vbi27_cc_by_osd==0x01 || *ccg_vbi27_cc_by_osd==0x02|| *ccg_vbi27_cc_by_osd==0x05|| *ccg_vbi27_cc_by_osd==0x06);
					push_2 = ( XDS ||  *ccg_vbi27_cc_by_osd==0x00 || *ccg_vbi27_cc_by_osd==0x03 || *ccg_vbi27_cc_by_osd==0x04|| *ccg_vbi27_cc_by_osd==0x07|| *ccg_vbi27_cc_by_osd==0x08);
						
					if((g_user_data[rd_idx][i*3+7]&0x03) == 0x00)//NTSC_CC_FIELD_1
					{
						for(j=0;j<8;j++)//pariety check
						{
							if( (((g_user_data[rd_idx][i*3+8])>>j)&0x01) == 0x01) pariety_check_1 += 1;
							if( (((g_user_data[rd_idx][i*3+9])>>j)&0x01) == 0x01) pariety_check_2 += 1;
							//libc_printf("%3x - %3x\n",(g_user_data[rd_idx][i*3+8]),(g_user_data[rd_idx][i*3+9]));
						}
						if( (pariety_check_1 % 2)==0 || (pariety_check_2 % 2)==0 ) continue;

						cc_field=1;
						//libc_printf("Test1 (%d)(%d)",ccg_vbi27_pconfig_par->cc_by_vbi,g_disable_vbioutput); //vicky20110224
						if(TRUE == ccg_vbi27_pconfig_par->cc_by_vbi && g_disable_vbioutput==FALSE)
						{
							#if((SYS_MAIN_BOARD>=BOARD_DB_M3811_01V01)&&(SYS_MAIN_BOARD<=BOARD_DB_M3812_03V01)) //for bug#3376
							m36g_tve_hd_write_cc(1,(g_user_data[rd_idx][i*3+9]<<8)|g_user_data[rd_idx][i*3+8]);
							#else
							sub_sdhd_write_cc_data(1,(g_user_data[rd_idx][i*3+9]<<8)|g_user_data[rd_idx][i*3+8]); // 1:top, 0:bot
							#endif
							//dwF1cnt++;
							//libc_printf("[1]");
							//libc_printf("(%x,%x)",g_user_data[rd_idx][i*3+9],g_user_data[rd_idx][i*3+8]);
						}	
						//ccvbi_CC=TRUE;	
						if(ccg_disable_process_cc==TRUE) 
						{
							//soc_printf("ccrecv_PAC=%d\n",ccrecv_PAC);
							ccrecv_PAC=FALSE;
							//MEMSET(g_user_data[rd_idx],0x00,USER_DATA_LENGTH_MAX);
							//return;
						}	
					
						if(push_1 )//cc1 cc2 tt1 tt2
						{
							if(NULL != g_vbi_priv->vbi_line21_push_by_cc)
							{
								cc_push_field(cc_field);
								g_vbi_priv->vbi_line21_push_by_cc((byte1<<8)|byte2);

						}
					}
//						
						}
					else if((g_user_data[rd_idx][i*3+7]&0x03) == 0x01)//NTSC_CC_FIELD_2
					{
					
						for(j=0;j<8;j++)//pariety check
						{
							if( (((g_user_data[rd_idx][i*3+8])>>j)&0x01) == 0x01) pariety_check_1 += 1;
							if( (((g_user_data[rd_idx][i*3+9])>>j)&0x01) == 0x01) pariety_check_2 += 1;
						}
						if( (pariety_check_1 % 2)==0 || (pariety_check_2 % 2)==0 ) continue;
						
						cc_field=2;
						if(TRUE == ccg_vbi27_pconfig_par->cc_by_vbi && g_disable_vbioutput==FALSE)
						{
							#if((SYS_MAIN_BOARD>=BOARD_DB_M3811_01V01)&&(SYS_MAIN_BOARD<=BOARD_DB_M3812_03V01)) //for bug#3376
							m36g_tve_hd_write_cc(0,(g_user_data[rd_idx][i*3+9]<<8)|g_user_data[rd_idx][i*3+8]);
							#else
							sub_sdhd_write_cc_data(0,(g_user_data[rd_idx][i*3+9]<<8)|g_user_data[rd_idx][i*3+8]); // 1:top, 0:bot
							#endif
							//dwF2cnt++;
							//libc_printf("[0]");
							//libc_printf("<%x,%x>",g_user_data[rd_idx][i*3+9],g_user_data[rd_idx][i*3+8]);
						}	
		//ccvbi_CC=TRUE;
						if(ccg_disable_process_cc==TRUE) 
						{
							ccrecv_PAC=FALSE;
							//MEMSET(g_user_data[rd_idx],0x00,USER_DATA_LENGTH_MAX);
							//return;
						}
						
						if(push_2 )//cc3 cc4 tt3 tt4
						{		//vicky20110124 add {}
							if(NULL != g_vbi_priv->vbi_line21_push_by_cc)
							{
								cc_push_field(cc_field);
								g_vbi_priv->vbi_line21_push_by_cc((byte1<<8)|byte2);
					        }
						}
					}
					//vicky20110210
					#ifdef CC_MONITOR_CS
						else if( ((g_user_data[rd_idx][i*3+7]&0x03) == 0x03) ||  ((g_user_data[rd_idx][i*3+7]&0x03) == 0x02) ) 
					#else
						else if((((g_user_data[rd_idx][i*3+7]&0x03) == 0x03) || ((g_user_data[rd_idx][i*3+7]&0x03) == 0x02)) && (g_dtv_cc_service !=0) && (*ccg_vbi27_cc_by_osd==0x00))  //xing 20070522 for DTVCC Packet Start 
					#endif
					{ 
						if(NULL != g_vbi_priv->vbi_line21_push_by_dtvcc)
						{
								if((g_user_data[rd_idx][i*3+7]&0x03) == 0x03)
								{
									//soc_printf("\n==================start packet =================\n");
									g_vbi_priv->vbi_line21_push_by_dtvcc((0xff<<8)|0xff );
								}	

								//soc_printf("s => ,%x,%x\n",g_user_data[rd_idx][i*3+8],g_user_data[rd_idx][i*3+9] );
								#if 0
								unsigned int in1,in2;
								in1=g_user_data[rd_idx][i*3+8];
								in2=g_user_data[rd_idx][i*3+9];
								if(	(in1 <0x80)	&&	(in1 >=0x20) && (in2 <0x80)	&&	(in2 >=0x20)	)
									libc_printf("%c %c",(g_user_data[rd_idx][i*3+8]),(g_user_data[rd_idx][i*3+9])); //vicky20110210 dbg
								#endif							
								g_vbi_priv->vbi_line21_push_by_dtvcc((((g_user_data[rd_idx][i*3+8])&0XFF)<<8)|(g_user_data[rd_idx][i*3+9])&0XFF);
						}
					}
					if(byte1==0x0f) XDS = FALSE;
				}
			}
		}
		g_user_data_array_cnt--;
		g_user_data_array_rd = (g_user_data_array_rd==USER_DATA_ARRAY_MAX-1)?0:g_user_data_array_rd+1;
	}
	//
}

/********************************************
* NAME: RequestVBIData
*       callback func to: 1 vbi output, 2 push user data for cc and dtvcc using
*
* Returns : void
*
* Parameter     				Flow    Description
* ------------------------------------------------------------------------------
* UINT8 FieldPolar				IN		no use
* ------------------------------------------------------------------------------
* Additional information:
******************************************/
void ccRequestVBIData(UINT8 FieldPolar)	//vicky20101229 dbg
{
	#if 0
	//vicky20110225 	
	static BOOL gfFirst=FALSE;
	static DWORD dwcnt=0;
	DWORD dwCurTime=0;
	static DWORD dwFirstTime=0;	
	
	dwcnt++;
	dwCurTime=OS_GetTickCount();
	if(!gfFirst)
	{
		dwFirstTime=OS_GetTickCount();
		dwcnt=0;
		dwF1cnt=0;
		dwF2cnt=0;
		gfFirst=TRUE;
	}
	else
	{
		if((dwCurTime-dwFirstTime)>=2000)
		{
			libc_printf("VBI Cnt(%d:F1(%d),F2(%d))\n",dwcnt,dwF1cnt,dwF2cnt);
			dwFirstTime=dwCurTime;
			dwcnt=0;
			dwF1cnt=0;
			dwF2cnt=0;
		}
	}
	//End
	#endif
	if(TRUE == ccg_vbi27_pconfig_par->cc_by_vbi)
		atsc_user_data_cc(FieldPolar);
}
/********************************************
* NAME: vbi_m3327_setoutput
*       set callback func
*
* Returns : void
*
* Parameter     				Flow    Description
* ------------------------------------------------------------------------------
* struct vbi_device	*dev		IN	no use
* T_VBIRequest *pVBIRequest	IN/OUT	callback point
* ------------------------------------------------------------------------------
* Additional information:
******************************************/
void ccvbi_m3327_setoutput(struct vbi_device *dev,T_VBIRequest *pVBIRequest)
{
	*pVBIRequest = ccRequestVBIData;
}
/********************************************
* NAME: vbi_cc_open
*       init cc task
*
* Returns : void
*
* Parameter     				Flow    Description
* ------------------------------------------------------------------------------
* struct vbi_device	*dev		IN	vbi dev
* ------------------------------------------------------------------------------
* Additional information:
******************************************/
INT32 vbi_cc_open(struct vbi_device *dev)
{
	struct vbi_m3327_private *tp = dev->priv;

	if(NULL != tp->init_cc_decoder)
	{
		tp->init_cc_decoder(dev);
	}

	return RET_SUCCESS;
}
#ifdef	CC_BY_OSD	//vicky20101229 dbg
/********************************************
* NAME: CCParsing_Task
*       cc task
*
* Returns : void
*
* Parameter     				Flow    Description
* ------------------------------------------------------------------------------
* UINT32 param1				IN	no use
* UINT32 param2				IN	no use
* ------------------------------------------------------------------------------
* Additional information:
* EAS will disable cc_parsing and cc_parsing_dtvcc
* cc_parsing_dtvcc will disable if enable cc decode
******************************************/
void CCParsing_Task(UINT32 param1,UINT32 param2)
{
	Dtvcc_init();
	while(1) // run forever when task exist.
	{
		osal_task_sleep(5); //for atsc,speed up cc_parsing()
		
		eas_text_scroll();
		
		//if(*ccg_vbi27_cc_by_osd != 0)   
			cc_parsing();// can't turn off this parsing for parsing v-chip data for rating lock setting			
		#ifdef CC_MONITOR_CS	//vicky20110210
			if (1)
		#else	
			if(g_dtv_cc_service != 0 && *ccg_vbi27_cc_by_osd == 0)//xing for DTVCC	
		#endif
			{
				cc_parsing_dtvcc();
			}
	}//end main while loop
}

/********************************************
* NAME: vbi_m3327_init_cc_decoder
*       init atsc closecaption decoder
*
* Returns : void
*
* Parameter     				Flow    Description
* ------------------------------------------------------------------------------
* struct vbi_device	*dev		IN	vbi dev
* ------------------------------------------------------------------------------
* Additional information:
******************************************/
OSAL_ID vbidec_tsk_id;
OSAL_ID vbidec_flag_id;
void vbi_m3327_init_cc_decoder(struct vbi_device *dev)
{	
	OSAL_T_CTSK t_ctsk;

	t_ctsk.task = (FP)CCParsing_Task;
	t_ctsk.para1 = (UINT32)dev;
	t_ctsk.para2 = 0;
	//t_ctsk.stksz = 0x0C00;
	t_ctsk.stksz = 0x0F00;//5k
	t_ctsk.quantum = 10;
	t_ctsk.itskpri = OSAL_PRI_NORMAL;
#ifdef _TDS_INFO_MONITOR
    t_ctsk.name[0] = 'V';
    t_ctsk.name[1] = 'B';
    t_ctsk.name[2] = '1';
#endif

	vbidec_tsk_id = osal_task_create(&t_ctsk);
	if(OSAL_INVALID_ID==vbidec_tsk_id)
	{
	        VBI_PRINTF("Can not create VBIDec_Task!!!\n");
		 VBI_ASSERT(0);
	}
}
/********************************************
* NAME: vbi_enable_cc_by_osd
*       enable cc by osd
*
* Returns : void
*
* Parameter     				Flow    Description
* ------------------------------------------------------------------------------
* struct vbi_device	*dev		IN	vbi dev
* ------------------------------------------------------------------------------
* Additional information:
* no use now, when compile atsc project, vbi_cc_init will set these parameters.
******************************************/
void vbi_enable_cc_by_osd(struct vbi_device*dev)
{
	struct vbi_m3327_private *priv = (struct vbi_m3327_private *)(dev->priv);

	priv->cc_by_osd = TRUE;
	priv->init_cc_decoder = vbi_m3327_init_cc_decoder;
	priv->vbi_line21_push_by_cc = vbi_line21_push;	
	priv->vbi_line21_push_by_dtvcc = vbi_line21_push_dtvcc;//xing for DTVCC
}
#endif //vicky20101229 dbg
#endif

